﻿app.controller("pushmessage", ["$scope", "$timeout", "toastr", "systrayService", "widgetService",
    function ($scope, $timeout, toastr, systrayService, widgetService) {
        $scope.targetWidget = null;
        $scope.targetWidgets = [];

        $scope.init = function () {
            systrayService.disable();

            widgetService.loadWidgets()
                .then(function(httpResponse) {
                    $scope.targetWidgets = httpResponse.data;
                });
        };

        $scope.push = function() {
            widgetService.pushMessage($scope.targetWidget.widgetId, $scope.targetWidget.sampleMessage)
                .then(function (httpResponse) {
                    if (httpResponse.status === 202) {
                        toastr.success("Message pushed to widget", "Yay!");
                    } else {
                        toastr.error("Message failed", "Dang it!");
                    }
                });
        };

        $timeout(function() {
            $scope.init();
        }, 5);
    }
]);